<?php

namespace app\api\controller;
use app\api\common\Common;
use app\api\common\ApiErrDesc;

class Category extends Common {
    /**
     * 产品分类(顶级)
     * @return  [JSON]    [返回顶级分类信息]
     */
    public function top_category(){
        // $dataurl = $this->__DATAURL__;
        $list = db('category')->where('tid=1')->field('id,tid,name')->select();
        if($list) {
			$this->return_msg(ApiErrDesc::SUCCESS[0], ApiErrDesc::SUCCESS[1], $list);
		}else{
			$this->return_msg(ApiErrDesc::ERROR[0], ApiErrDesc::ERROR[1]);
		}
    }

    /**
     * 产品分类（根据顶级id查子级）
     * @return  [JSON]    [返回二级分类信息]
     */
    public function second_category(){
        $data = $this->params;
        $dataurl = $this->__DATAURL__;
        $catList = db('category')->where('tid='.$data['top_id'])->field('id,name,bz_1')->select();
        foreach ($catList as $k => $v) {
            $catList[$k]['bz_1'] = $dataurl.$v['bz_1'];
        }
        if($catList) {
			$this->return_msg(ApiErrDesc::SUCCESS[0], ApiErrDesc::SUCCESS[1], $catList);
		}else{
			$this->return_msg(ApiErrDesc::ERROR[0], ApiErrDesc::ERROR[1]);
		}
    }
}